package com.example.pt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.pt.dto.FavoriteDTO;
import com.example.pt.entity.TorrentFavorite;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 种子收藏Mapper
 */
@Mapper
public interface TorrentFavoriteMapper extends BaseMapper<TorrentFavorite> {
    
    /**
     * 获取用户收藏的种子列表
     */
    @Select("SELECT f.id, t.tid, t.title, t.category, t.format, t.upload_time, " +
           "t.download_count, t.file_size, t.view_count, t.seeder_count, " +
           "f.create_time, f.note " +
           "FROM torrent_favorite f " +
           "JOIN torrentFile t ON f.tid = t.tid " +
           "WHERE f.uid = #{uid} " +
           "ORDER BY f.create_time DESC")
    List<FavoriteDTO> findUserFavorites(@Param("uid") Integer uid);
    
    /**
     * 检查用户是否已收藏特定种子
     */
    @Select("SELECT COUNT(*) FROM torrent_favorite WHERE uid = #{uid} AND tid = #{tid}")
    int checkUserFavorite(@Param("uid") Integer uid, @Param("tid") Integer tid);
    
    /**
     * 根据用户ID和种子ID删除收藏
     */
    @Delete("DELETE FROM torrent_favorite WHERE uid = #{uid} AND tid = #{tid}")
    int removeUserFavorite(@Param("uid") Integer uid, @Param("tid") Integer tid);
} 